package com.example.jn_dxs.Ui.fragment;

import android.content.Intent;
import android.view.View;

import com.example.jn_dxs.Base.BaseFragment;
import com.example.jn_dxs.Base.BaseViewModel;
import com.example.jn_dxs.R;
import com.example.jn_dxs.Ui.activity.ChangePassWordActivity;
import com.example.jn_dxs.Utlis.SPCommon;
import com.example.jn_dxs.databinding.FragmentMapBinding;
import com.example.jn_dxs.databinding.FragmentMineBinding;
import com.example.jn_dxs.view.LogoutDialog;

public class MineFragment extends BaseFragment<BaseViewModel, FragmentMineBinding> {
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void loadData() {
        binding.MyTopBar.tvBack.setVisibility(View.GONE);
        binding.MyTopBar.tvTitle.setText("个人信息");
        binding.MyTopBar.tvRight.setText("修改");
        binding.MyTopBar.tvRight.setVisibility(View.VISIBLE);
        binding.MyTopBar.tvRight.setOnClickListener(v -> {
            if (binding.MyTopBar.tvRight.getText().equals("修改")) {
                binding.MyTopBar.tvRight.setText("完成");
                binding.Name.setFocusable(true);
                binding.Name.setFocusableInTouchMode(true);
                binding.Unit.setFocusable(true);
                binding.Unit.setFocusableInTouchMode(true);
                binding.Division.setFocusable(true);
                binding.Division.setFocusableInTouchMode(true);
                binding.Phone.setFocusable(true);
                binding.Phone.setFocusableInTouchMode(true);
                binding.Position.setFocusable(true);
                binding.Position.setFocusableInTouchMode(true);
            } else {
                binding.MyTopBar.tvRight.setText("修改");
                binding.Name.setFocusable(false);
                binding.Unit.setFocusable(false);
                binding.Division.setFocusable(false);
                binding.Phone.setFocusable(false);
                binding.Position.setFocusable(false);
            }
        });

        binding.ChangePassword.setOnClickListener(v -> {
            startActivity(new Intent(activity, ChangePassWordActivity.class));
        });
        binding.LogOut.setOnClickListener(v -> {
            //退出登录
            LogoutDialog dialog = new LogoutDialog(activity);
            dialog.setTltMsg("是否退出登录");
            dialog.setNoStr("取消");
            dialog.setYesStr("退出");
            dialog.setYesTextColor(R.color.logout);
            dialog.setNoOnclickListener(view -> {
                dialog.dismiss();
            });
            dialog.setYesOnclickListener(view -> {
                dialog.dismiss();
                System.exit(0);
            });
            dialog.show();

        });
    }
}
